package com.maila.simplerecord.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.maila.simplerecord.R;
import com.maila.simplerecord.data.ProjectProgressdata;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/6/2.
 */

public class ProgressAdapter extends BaseAdapter {
    Context context;
    List<ProjectProgressdata> mdatas;

    public ProgressAdapter(Context context) {
        this.context = context;
        mdatas = new ArrayList<>();
    }

    public void setImgs(List<ProjectProgressdata> imgs) {
        this.mdatas = imgs;
        notifyDataSetChanged();
    }

    public void addallImgs(List<ProjectProgressdata> imgs) {
        this.mdatas.addAll(imgs);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mdatas.size();
    }

    @Override
    public ProjectProgressdata getItem(int position) {
        return  mdatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_subd_progress, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
            AutoUtils.autoSize(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.subjectTime1.setText(mdatas.get(position).subject_time);
        holder.subjectContent1.setText(mdatas.get(position).subject_content);
        holder.subjectContent2.setText(mdatas.get(position).subject_note);
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.subject_time1)
        TextView subjectTime1;
        @BindView(R.id.subject_content1)
        TextView subjectContent1;
        @BindView(R.id.subject_content2)
        TextView subjectContent2;
        @BindView(R.id.ll_progress1)
        AutoLinearLayout llProgress1;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
